package cn.edu.neusoft.demo.hospital2.Dao;

import cn.edu.neusoft.demo.hospital2.pojo.DoctorWork;
import cn.edu.neusoft.demo.hospital2.pojo.WorkPlan;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface WorkPlanDao extends BaseMapper<WorkPlan> {
    @Results(value = {
            @Result(id = true, property = "day", column = "day"),
            @Result(property = "weekday", column = "weekday"),
            @Result(property = "status", column = "status"),
            @Result(property = "createBy", column = "create_by")
    })
        // 查询所有工作计划
    List<WorkPlan> getAllWorkPlans();

    // 根据日期查询工作计划
    WorkPlan getWorkPlanByDay(java.sql.Date day);

    // 新增工作计划
    int addWorkPlan(WorkPlan workPlan);

    // 修改工作计划
    int updateWorkPlan(WorkPlan workPlan);

    // 删除工作计划
    int deleteWorkPlan(java.sql.Date day);

    @Select("select DATE_FORMAT(day, '%Y-%m-%d') as day,weekday,status,create_by from work_plan where year(day)=${year} and month(day)=${month} and day(day)=${day}")
    WorkPlan selectByDay(@Param("year") int year, @Param("month") int month,
                         @Param("day") int day);

    @Update("update work_plan set status=${status} where day='${day}'")
    int updateByDay(@Param("day") String day, @Param("status") int status);

    @Select("select dw.* from doctor_work dw,work_plan wp where dw.day=DATE_FORMAT(wp.day, '%Y-%m-%d') and wp.status=1 and dw.day in (${week})")
    List<DoctorWork> getWorkPlanByWeek(String week);
}